/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bookshare;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Michal
 */
@WebServlet(name = "BewertungServlet", urlPatterns = {"/BewertungServlet"})
public class BewertungServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    
    public BewertungServlet () {
        super();
    }
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
/*		HttpSession session = request.getSession(true);
		int userid = (Integer)session.getAttribute("userID");
*/    	SQLabfrage abfrage = new SQLabfrage();
        int bewertung = Integer.parseInt(request.getParameter("bewertung"));
        String werWirdBewertet = request.getParameter("werWirdBewertet");
        String artikelart = request.getParameter("artikelart");
        // ID des Artikels
        String strID = request.getParameter("strID");
        int artikelid = Integer.parseInt(strID);
        if(bewertung < 1 || bewertung > 5) {
            response.sendRedirect("index.jsp?param1=profil&param3="+strID+"&param4=bewertung_error");
            return;
        }
        try {
            abfrage.setBewertung(bewertung, werWirdBewertet, artikelid, artikelart);
        } catch (Exception e) {}
        response.sendRedirect("index.jsp?param1=profil&param3="+strID+"&param4=bewertung_success");
    }
}
